package com.situ.hospital.user.service;

import java.sql.SQLException;
import java.util.List;

import com.situ.hospital.user.dao.IUserDao;
import com.situ.hospital.user.dao.impl.UserDaoImpl;
import com.situ.hospital.user.model.UserModel;

public class UserService {
	public Integer insert(UserModel user) throws SQLException {
		IUserDao ud = new UserDaoImpl();
		UserModel user2 = new UserModel();
		user2.setUsername(user.getUsername());
		List<UserModel> list = ud.selectModel(user2);
		if (list.size() == 0 || list == null) {
//			System.out.println(1);
			ud.insert(user);
//			System.out.println(2);
			return 1;
		} else {
			return 0;
		}

	}

	public Integer login(UserModel user) throws SQLException {
		IUserDao ud = new UserDaoImpl();
		UserModel user2 = new UserModel();
		user2.setUsername(user.getUsername());
		List<UserModel> list = ud.selectModel(user2);
		if (list.size() == 0 || list == null) {
			return 2;
		} else {
			if (user.getPassword().equals(list.get(0).getPassword())) {
				return 1;
			} else {
				return 3;
			}

		}
	}
}
